package com.bub.pay.core.base;

import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

public abstract class BaseManagerAbstract<T, M extends Mapper<T>> implements IBaseManager<T> {

    @Autowired
    protected Mapper<T> baseMapper;

    public M getBaseMapper() {
        return (M) baseMapper;
    }

    @Override
    public int insert(T entity) {
        return getBaseMapper().insert(entity);
    }

    @Override
    public int insertSelective(T entity) {
        return getBaseMapper().insertSelective(entity);
    }

    @Override
    public int updateByPrimary(T entity) {
        return getBaseMapper().updateByPrimaryKey(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(T entity) {
        return getBaseMapper().updateByPrimaryKeySelective(entity);
    }

    @Override
    public int updateByExampleSelective(T entity,Object example){
        return getBaseMapper().updateByExampleSelective(entity,example);
    }

    @Override
    public T getById(Long id) {
        return getBaseMapper().selectByPrimaryKey(id);
    }
    @Override
    public T getByPrimaryKey(Object var1) {
        return getBaseMapper().selectByPrimaryKey(var1);
    }

    @Override
    public T getOne(T entity) {
        return getBaseMapper().selectOne(entity);
    }

    @Override
    public int getCount(T entity) {
        return getBaseMapper().selectCount(entity);
    }

    @Override
    public List<T> getList(T entity) {
        return getBaseMapper().select(entity);
    }

    @Override
    public List<T> getAll() {
        return getBaseMapper().selectAll();
    }

    @Override
    public Integer getCountByExample(Example example){
        return getBaseMapper().selectCountByExample(example);
    }

    @Override
    public List<T> getByExample(Example example){
        return getBaseMapper().selectByExample(example);
    }

    @Override
    public T getOneByExample(Example example){
        return getBaseMapper().selectOneByExample(example);
    }

}
